<?php
/**
 * Created by JetBrains PhpStorm.
 * User: porterzhang
 * Date: 13-3-19 下午3:34
 * To change this template use File | Settings | File Templates.
 */
if (!defined('IN_MOBILE_API')) {
    exit('Access Denied');
}

include_once 'forum.php';
class cloud_api {
    function common() {
        global $_G;
        //判断是不是登录用户
        if (empty($_GET['updatatype'])) {
            $variable = array(
                'code' => 1001,
                'messagestr' => lang('plugin/cloud', '1001'),
            );
            cloud_core::result(cloud_core::variable($variable));
        }

        //如果要添加上传类型的话
        //1.在下面的array增加要上传的类型
        //2.在cloud.class.php页面的这个get_target_dir方法中增加type类型，方便建立文件夹
        //3.在discuz_upload.php页面的这个check_dir_type方法中的array中增加上传的类型
        if (!in_array($_GET['updatatype'], array('product', 'article', 'adpic', 'richtext'))) {
            $variable = array(
                'code' => 1036,
                'messagestr' => lang('plugin/cloud', '1036'),
            );
            cloud_core::result(cloud_core::variable($variable));
        }

        //上传文件
        $_FILES['Filedata']['name'] = addslashes(diconv(urldecode($_FILES['Filedata']['name']), 'UTF-8'));
        $_FILES['Filedata']['type'] = $_GET['filetype'];
        //初始化上传的文件信息
        $file = plugin_cloud::update_init($_FILES['Filedata'], $_GET['updatatype']);
        //保存到指定的文件夹中
        plugin_cloud::saveUpload($file);
        //将图片插入到数据库中，并返回id

        if ($_GET['updatatype'] == 'article') {
//            $insert = array(
//                'caid' => 0,
//                'name' => censor($file['name']),
//                'display' => empty($_GET['display']) ? 1 : $_GET['display'],
//                'url' => $file['attachment'],
//                'lasttime' => TIMESTAMP,
//            );
//            $caaid = C::t('#cloud#cloud_article_attachment')->insert($insert);
            plugin_cloud::uploadOtherMsg(0,  $file['attachment']);
//            plugin_cloud::uploadMsg(0, $caaid);
        }
        else if ($_GET['updatatype'] == 'product') {
            //将图片插入到数据库中，并返回id
            $fileOtherName = explode('.', censor($file['name']));
            $insert = array(
                'cpid' => $_GET['cpid'],
                'name' => empty($_GET['name']) ? $fileOtherName[0] : $_GET['name'],
                'display' => empty($_GET['display']) ? 1 : $_GET['display'],
                'url' => $file['attachment'],
                'lasttime' => TIMESTAMP,
            );
            $cppid = C::t('#cloud#cloud_product_photo')->insert($insert);
            plugin_cloud::uploadMsg(0, $cppid);
        }
        else if ($_GET['updatatype'] == 'adpic') {
            plugin_cloud::uploadOtherMsg(0,  $file['attachment']);
        }
        else if ($_GET['updatatype'] == 'richtext') {
            plugin_cloud::uploadOtherMsg(0, $_G['siteurl'] . 'data/attachment/richtext/' . $file['attachment']);
        }
    }

    function output() { }


}

?>

